home *** CD-ROM | disk | FTP | other *** search
/ Delphi Anthology / aDELPHI.iso / Runimage / Delphi50 / Source / Decision Cube / mxdcube.pas < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  21KB  |  748 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Borland Delphi Visual Component Library         }
  4. {                                                       }
  5. {       Copyright (c) 1997,99 Inprise Corporation       }
  6. {                                                       }
  7. {*******************************************************}
  8.  
  9. unit mxdcube;
  10.  
  11. interface
  12.  
  13. uses
  14.  Windows, Messages, Classes, SysUtils, Controls, StdCtrls, Graphics, dialogs,
  15.  DB, DBTables, Grids, Forms, mxConsts, mxgrid, mxdb, mxcommon, mxstore,
  16.  ExtCtrls, Buttons, ComCtrls, Menus, Mask;
  17.  
  18. type
  19.   ECubeDesignError = class(Exception);
  20.  
  21.   TEditorDimensionItem = class(TDimensionItem);
  22.  
  23.   TDssCubeEditor = class(TForm)
  24.     FieldList: TListBox;
  25.     RadioMetaData: TRadioButton;
  26.     RadioDimensionData: TRadioButton;
  27.     RadioAllData: TRadioButton;
  28.     RadioNoData: TRadioButton;
  29.     Panel1: TGroupBox;
  30.     CaptionEdit: TEdit;
  31.     CaptionLabel: TLabel;
  32.     ActiveLabel: TLabel;
  33.     BinLabel: TLabel;
  34.     StartLabel: TLabel;
  35.     TypeLabel: TLabel;
  36.     ActiveEdit: TComboBox;
  37.     BinEdit: TComboBox;
  38.     TypeEdit: TComboBox;
  39.     Pager: TPageControl;
  40.     DimensionInfo: TTabSheet;
  41.     MemoryControl: TTabSheet;
  42.     Label1: TLabel;
  43.     Label2: TLabel;
  44.     FormatEdit: TEdit;
  45.     StartEdit: TMaskEdit;
  46.     OKButton: TButton;
  47.     CancelButton: TButton;
  48.     HelpButton: TButton;
  49.     NActiveDims: TLabel;
  50.     nDemandDims: TLabel;
  51.     Label4: TLabel;
  52.     Label7: TLabel;
  53.     Label9: TLabel;
  54.     NActiveSums: TLabel;
  55.     NDemandSums: TLabel;
  56.     Label6: TLabel;
  57.     MaxDims: TEdit;
  58.     MaxSums: TEdit;
  59.     MaxCells: TEdit;
  60.     Label5: TLabel;
  61.     Label12: TLabel;
  62.     nDemandCells: TLabel;
  63.     GetCellCounts: TButton;
  64.     CubeLimits: TGroupBox;
  65.     ValueCount: TLabel;
  66.     Label3: TLabel;
  67.     nCurrDims: TLabel;
  68.     nCurrSums: TLabel;
  69.     nCurrCells: TLabel;
  70.     BaseNameLabel: TLabel;
  71.     BaseNameEdit: TMaskEdit;
  72.     procedure RadioDimensionDataClick(Sender: TObject);
  73.     procedure RadioMetaDataClick(Sender: TObject);
  74.     procedure RadioAllDataClick(Sender: TObject);
  75.     procedure RadioNoDataClick(Sender: TObject);
  76.     procedure FieldListClick(Sender: TObject);
  77.     procedure OKButtonClick(Sender: TObject);
  78.     procedure HandleFieldEdit(Sender: TObject);
  79.     procedure HandleBeginEdit(Sender: TObject; var Key: Char);
  80.     procedure ActiveEditChange(Sender: TObject);
  81.     procedure CancelButtonClick(Sender: TObject);
  82.     procedure PagerChange(Sender: TObject);
  83.     procedure GetCellCountsClick(Sender: TObject);
  84.     procedure FormKeyPress(Sender: TObject; var Key: Char);
  85.     procedure HelpButtonClick(Sender: TObject);
  86.     { Private declarations }
  87.   private
  88.     myObject: TDecisionCube;
  89.     myMap: TCubeDims;
  90.     myDataSet: TDataSet;
  91.     myDB: TDataBase;
  92.     bBinEdited: boolean;
  93.     bEditing: boolean;
  94.     bParsed: boolean;
  95.     bDataSetMatch: boolean;
  96.     fLastSelected: integer;
  97.     bForceRefresh: boolean;
  98.     bSetNameEditing: boolean;
  99.     bSetValuesEditing: boolean;
  100.     { editable field copies }
  101.     FNameCopy: String;
  102.     FFormatCopy: String;
  103.     FActiveCopy: TActiveFlags;
  104.     FTypeCopy:  TDimFlags;
  105.     FBinTypeCopy: TBinType;
  106.     FStartValueCopy: string;
  107.     procedure InitEdit;
  108.     procedure CommitEdit;
  109.     procedure GetValueCounts;
  110.     { Protected declarations }
  111.   protected
  112.     { Public declarations }
  113.   public
  114.     procedure UpdateLists;
  115.     procedure InitializePanel;
  116.     procedure InitCapacityPage;
  117.     function SInitialize(const Designer: IDesigner; AnObject: TComponent): boolean;
  118.     procedure SFinalize;
  119.     constructor Create(AOwner: TComponent); override;
  120.     destructor Destroy; override;
  121.   end;
  122.  
  123.   procedure ShowDSSCubeEditor(const Designer: IDesigner; aCube: TDecisionCube);
  124.  
  125. var
  126.   DSSCubeEditor: TDssCubeEditor;
  127.  
  128. implementation
  129.  
  130. {$R *.DFM}
  131.  
  132.  
  133.   { Query Editor }
  134.  
  135. procedure ShowDSSCubeEditor(const Designer: IDesigner; aCube: TDecisionCube);
  136. var
  137.   aWindow: TDssCubeEditor;
  138.   x,y: integer;
  139. begin
  140.   if not assigned(aCube) then Exit;
  141.   aWindow := TDssCubeEditor.Create(application);
  142.   try
  143.     if aWindow.SInitialize(Designer, aCube) then
  144.     begin
  145.       x := (Screen.Width - aWindow.Width) div 2;
  146.       y := (Screen.Height - aWindow.Height) div 2;
  147.       if (x < 0) then x := 0;
  148.       if (y < 0) then y := 0;
  149.       aWindow.Left := x;
  150.       aWindow.Top := y;
  151.       aWindow.ShowModal;
  152.     end;
  153.   finally
  154.     aWindow.free;
  155.   end;
  156. end;
  157.  
  158. constructor TDssCubeEditor.Create(AOwner: TComponent);
  159. begin
  160.   bSetNameEditing := false;
  161.   bSetValuesEditing := false;
  162.   bForceRefresh := false;
  163.   myMap := nil;
  164.   inherited Create(AOwner);
  165. end;
  166.  
  167. destructor TDssCubeEditor.Destroy;
  168. begin
  169.   myMap.free;
  170.   inherited Destroy;
  171. end;
  172.  
  173. function TDssCubeEditor.SInitialize(const Designer: IDesigner; anObject: TComponent): boolean;
  174. var
  175.   anError: TQueryError;
  176.   aliasname: string;
  177.   bDBexists: boolean;
  178. begin
  179.   Result := False;
  180.   if not (anObject is TDecisionCube) then Exit;
  181.   myObject := TDecisionCube(anObject);
  182.   myDataSet := myObject.DataSet;
  183.   if (not assigned(myDataSet)) then
  184.     raise ECubeDesignError.CreateRes(@sNoDataSet);
  185.   Pager.ActivePage := DimensionInfo;
  186.   if (myDataSet is TQuery) then
  187.   begin
  188.     bDBExists := (tquery(myDataSet).Database <> nil);
  189.     if not bDBExists then
  190.     begin
  191.       aliasName := TQuery(myDataSet).DataBaseName;
  192.       if (aliasName <> '') then
  193.         myDB := TQuery(myDataSet).DBSession.OpenDataBase(aliasName);
  194.     end;
  195.   end;
  196.   { Build the dimension map for this set }
  197.   myMap := TCubeDims.Create(myObject, TCubeDim);
  198.   myMap.Assign(TCubeDims(myObject.DimensionMap));
  199.   anError := BuildDataSetMap(myDataSet, myMap, bParsed, bDataSetMatch);
  200.   if (anError = tqeNotInitialized) then
  201.   begin
  202.     raise ECubeDesignError.CreateRes(@sQryNotInitialized);
  203.     Result := False;
  204.     Exit;
  205.   end;
  206.   MaxDims.text := inttostr(myObject.MaxDimensions);
  207.   MaxSums.text := inttostr(myObject.MaxSummaries);
  208.   maxCells.text := inttostr(myObject.MaxCells);
  209.   UpdateLists;
  210.   InitCapacityPage;
  211.   InitializePanel;
  212.   Result := True;
  213. end;
  214.  
  215. procedure TDssCubeEditor.SFinalize;
  216. var
  217.   i,dims, sums: integer;
  218.   ValueCount, CP: integer;
  219.   bEstimating: boolean;
  220. begin
  221.   CommitEdit;
  222.   dims := strtoint(MaxDims.text);
  223.   sums := strtoint(MaxSums.text);
  224.   if (myMap.ActiveDimensionCount > dims) then
  225.     raise ECubeDesignError.createResFmt(@sMaxAllowedDims,[dims]);
  226.   if (myMap.ActiveSummaryCount > sums) then
  227.     raise ECubeDesignError.createResFmt(@sMaxAllowedsums,[sums]);
  228.   myObject.MaxDimensions := dims;
  229.   myObject.MaxSummaries := sums;
  230.   myObject.MaxCells := strtoInt(MaxCells.text);
  231.   if (myObject.CurrentSummary <= sums) then
  232.     myObject.currentSummary := 0;
  233.   {
  234.     See if the valuecount information is still available.  If not, an attempt is
  235.     made to be friendly to the user by making a fairly pessimistic assumption about
  236.     the size of a dimension whose valuecount is not available.  If all AsNeeded or
  237.     Active Cells can still be loaded, no attempt is made to fetch the cell info
  238.     at this point.
  239.   }
  240.   if (myObject.maxCells > 0) then
  241.   begin
  242.     bEstimating := false;
  243.     CP := 1;
  244.     for i := 0 to myMap.count-1 do
  245.     begin
  246.       if (myMap[i].DimensionType = dimDimension) and (myMap[i].ActiveFlag <> diInactive) then
  247.       begin
  248.         ValueCount := myMap[i].ValueCount;
  249.         if (ValueCount <= 0) then
  250.         begin
  251.           bEstimating := true;
  252.           ValueCount := LargeValueCount;
  253.         end;
  254.         CP := CP * ValueCount;
  255.       end;
  256.     end;
  257.     if (CP > myObject.MaxCells) and bEstimating then
  258.     begin
  259.       if (MessageDlg(sGetValueCounts, mtConfirmation, [mbYes, mbNo], 0) = 6) then
  260.       begin
  261.         GetValueCounts;
  262.       end;
  263.     end;
  264.   end;
  265.   for i := 0 to myMap.count-1 do
  266.   begin
  267.     myMap[i].ActiveFlag := myMap[i].ActiveFlag; { resets the Active boolean }
  268.   end;
  269.   myObject.Refresh(myMap, bForceRefresh);
  270.   UpdateDesigner(myObject);
  271. end;
  272.  
  273. procedure TDssCubeEditor.UpdateLists;
  274. var
  275.   i: Integer;
  276.   DM: TCubeDim;
  277. begin
  278.   FieldList.Clear;
  279.   for I := 0 to myMap.count-1 do
  280.   begin
  281.     DM := myMap[i];
  282.     if DM.loaded then
  283.       FieldList.Items.Add(DM.FieldName + '*')
  284.     else
  285.       FieldList.Items.Add(DM.FieldName);
  286.   end;
  287. end;
  288.  
  289. procedure TDssCubeEditor.InitializePanel;
  290. begin
  291.   if (FieldList.items.count > 0) then FieldList.itemindex := 0;
  292.   fLastSelected := FieldList.itemindex;
  293.   InitEdit;
  294.   if (csDesigning in myObject.ComponentState) then
  295.   begin
  296.     case myObject.DesignState of
  297.       dsMetaData      : RadioMetaData.Checked := True;
  298.       dsDimensionData : RadioDimensionData.Checked := true;
  299.       dsAllData       : RadioAllData.Checked := true;
  300.       dsNoData        : RadioNoData.Checked := true;
  301.     end;
  302.   end
  303.   else
  304.   begin
  305.     RadioMetaData.Enabled := false;
  306.     RadioDimensionData.Enabled := false;
  307.     RadioAllData.Enabled := false;
  308.     RadioNoData.Enabled := false;
  309.     GetCellCounts.visible := false;
  310.     MaxCells.enabled := false;
  311.     MaxDims.enabled := false;
  312.     MaxSums.enabled := false;
  313.   end;
  314. end;
  315.  
  316. procedure TDssCubeEditor.FieldListClick(Sender: TObject);
  317. begin
  318.   try
  319.     CommitEdit;
  320.   except
  321.     on E: exception do
  322.     begin
  323.       raise Exception.create(E.Message);
  324.       Exit;
  325.     end;
  326.   end;
  327.   fLastSelected := fieldList.itemIndex;
  328.   InitEdit;
  329. end;
  330.  
  331. procedure TDssCubeEditor.InitEdit;
  332. var
  333.   DM: TCubeDim;
  334. begin
  335.   if (fLastSelected >= 0) and (fLastSelected < MyMap.count) then
  336.   begin
  337.     DM := myMap[fLastSelected];
  338.     ValueCount.Caption := inttostr(DM.ValueCount);
  339.     FActiveCopy := DM.ActiveFlag;
  340.     FNameCopy := DM.Name;
  341.     FTypeCopy := DM.DimensionType;
  342.     FFormatCopy := DM.Format;
  343.     ActiveEdit.itemindex := ord(DM.ActiveFlag);
  344.     TypeEdit.itemindex := ord(DM.DimensionType);
  345.     TypeEdit.Enabled := (not bParsed) or not (myDataSet is TQuery);
  346.     CaptionEdit.text := DM.Name;
  347.     CaptionEdit.enabled := not (AnsiUpperCase(DM.Name) = sCountStar);
  348.     BaseNameEdit.text := DM.BaseName;
  349.     BaseNameEdit.visible := (not bParsed) or not (myDataSet is TQuery);
  350.     BaseNameLabel.visible := (not bParsed) or not (myDataSet is TQuery);
  351.     FormatEdit.Text := DM.Format;
  352.     BinEdit.Itemindex := ord(TCubeDim(DM).BinType);
  353.     FBinTypeCopy := TCubeDim(DM).BinType;
  354.     if (DM.DimensionType = dimDimension) then
  355.     begin
  356.       BinEdit.enabled := true;
  357.       BinLabel.Enabled := true;
  358.       if (DM.FieldType in [ftDate,ftDateTime]) and (DM.BinType in [binQuarter,binMonth,binYear])then
  359.       begin
  360.         FStartValueCopy := TCubeDim(DM).StartValue;
  361.         StartEdit.text := TCubeDim(DM).StartValue;
  362.         StartEdit.enabled := true;
  363.         StartLabel.enabled := true;
  364.       end
  365.       else if (DM.BinType = binSet) then
  366.       begin
  367.         StartEdit.enabled := true;
  368.         StartLabel.enabled := true;
  369.         StartEdit.Text := DM.StartValue;
  370.       end
  371.       else
  372.       begin
  373.         StartEdit.Text := '';
  374.         StartEdit.enabled := false;
  375.         StartLabel.enabled := false;
  376.       end;
  377.     end
  378.     else
  379.     begin
  380.       BinEdit.enabled := false;
  381.       BinLabel.enabled := false;
  382.       StartEdit.Text := '';
  383.       StartEdit.enabled := false;
  384.       StartLabel.enabled := false;
  385.     end;
  386.   end
  387.   else
  388.   begin
  389.     ActiveEdit.itemindex := -1;
  390.     FormatEdit.text := '';
  391.     CaptionEdit.text := '';
  392.     BaseNameEdit.Text := '';
  393.     TypeEdit.itemindex := -1;
  394.     BinEdit.itemindex := -1;
  395.     StartEdit.text := '';
  396.   end;
  397.  
  398.   bEditing := false;
  399.   bBinEdited := false;
  400. end;
  401.  
  402. procedure TDssCubeEditor.CommitEdit;
  403. var
  404.   OldDM, DM: TCubeDim;
  405.   newBinType: tBinType;
  406.   ValueCount: Integer;
  407. begin
  408.   if bEditing and (fLastSelected >= 0) and (fLastSelected < myMap.count) then
  409.   begin
  410.     DM := myMap[fLastSelected];
  411.     DM.DimensionType := TDimFlags(TypeEdit.itemindex);
  412.     DM.ActiveFlag := TActiveFlags(ActiveEdit.itemindex);
  413.     DM.Name := CaptionEdit.text;
  414.     if (not bParsed) or not (myDataSet is TQuery) then
  415.       DM.BaseName := BaseNameEdit.Text;
  416.     DM.Format := FormatEdit.text;
  417.     if bBinEdited then
  418.     begin
  419.       { estimate the valuecount of this new bin, based on the old one, if possible }
  420.       ValueCount := 0;
  421.       newBinType := TBinType(BinEdit.ItemIndex);
  422.       if (myObject.DimensionMap.count > fLastSelected) then
  423.       begin
  424.         oldDM := myObject.DimensionMap[fLastSelected];
  425.         if (OldDM.BinType = NewBinType) then
  426.           ValueCount := OldDM.ValueCount
  427.         else
  428.           case newBinType of
  429.           binMonth:
  430.           begin
  431.             if (OldDM.BinType = binQuarter) then
  432.               ValueCount := OldDM.ValueCount * 3
  433.             else if (OldDM.BinType = binYear) then
  434.               ValueCount := OldDM.ValueCount * 12;
  435.           end;
  436.           binQuarter:
  437.           begin
  438.             if (OldDM.BinType = binMonth) then
  439.               ValueCount := OldDM.ValueCount div 3
  440.             else if (OldDM.BinType = binYear) then
  441.               ValueCount := OldDM.ValueCount * 4;
  442.           end;
  443.           binYear:
  444.           begin
  445.             if (OldDM.BinType = binMonth) then
  446.               ValueCount := OldDM.ValueCount div 12
  447.             else if (OldDM.BinType = binQuarter) then
  448.               ValueCount := OldDM.ValueCount div 4;
  449.           end;
  450.           binSet:
  451.           begin
  452.             ValueCount := 2;
  453.           end;
  454.           binNone:
  455.           begin
  456.             if (OldDM.BinType = binSet) and assigned (OldDM.BinData) then
  457.               ValueCount := OldDM.BinData.GetAllBinValueCount;
  458.           end;
  459.         end;
  460.       end;
  461.       try
  462.         DM.BinType := TBinType(BinEdit.ItemIndex);
  463.         if (DM.FieldType in [ftDate,ftDateTime]) and (DM.BinType in [binQuarter,binYear,binMonth]) then
  464.         begin
  465.           if (StartEdit.text <> '') then
  466.             TCubeDim(DM).StartValue := DatetoStr(StrtoDate(StartEdit.text));
  467.         end
  468.         else if (DM.BinType = binSet) then
  469.         begin
  470.           DM.StartValue := StartEdit.text;
  471.         end;
  472.       except
  473.         on exception do
  474.         begin
  475.           FieldList.itemIndex := fLastSelected;
  476.           raise ECubeDesignError.createRes(@sIllegalValueForBin);
  477.         end;
  478.       end;
  479.       DM.ValueCount := ValueCount;
  480.     end;
  481.   end;
  482.   bBinEdited := false;
  483.   bEditing := false;
  484. end;
  485.  
  486. procedure TDSSCubeEditor.InitCapacityPage;
  487. var
  488.   i: integer;
  489.   iActiveSums, iNeededSums, ICurrSums: integer;
  490.   iActiveDims, iNeededDims, iCurrDims: integer;
  491.   iNeededCP, iActiveCP, iCurrCP: integer;
  492. begin
  493.   if not assigned(myMap) then Exit;
  494.   iActiveSums := 0;
  495.   iNeededSums := 0;
  496.   iCurrSUms := 0;
  497.   iActiveDims := 0;
  498.   iNeededDims := 0;
  499.   iCurrDims := 0;
  500.   iNeededCP := 1;
  501.   iActiveCP := 1;
  502.   iCurrCP := 1;
  503.   for i := 0 to myMap.count-1 do
  504.   begin
  505.     if (myMap[i].DimensionType = dimDimension) then
  506.     begin
  507.       if (myMap[i].Loaded) then
  508.       begin
  509.         iCurrDims := iCurrDims + 1;
  510.         if (myMap[i].ValueCount <= 0) then
  511.           iCurrCP := 0
  512.         else
  513.           iCurrCP := iCurrCP * myMap[i].ValueCount;
  514.       end;
  515.       case myMap[i].ActiveFlag of
  516.         diActive:
  517.         begin
  518.           iActiveDims := iActiveDims + 1;
  519.           if (myMap[i].ValueCount <= 0) then
  520.             iActiveCP := 0
  521.           else
  522.             iActiveCP := iActiveCP * myMap[i].ValueCount;
  523.         end;
  524.         diAsNeeded:
  525.         begin
  526.           iNeededDims := iNeededDims + 1;
  527.           if (myMap[i].ValueCount <= 0) then
  528.             iNeededCP := 0
  529.           else
  530.             iNeededCP := iNeededCP * myMap[i].ValueCount;
  531.         end;
  532.       end;
  533.     end
  534.     else if (myMap[i].derivedfrom < 0) then
  535.     begin
  536.       if (myMap[i].loaded) then iCurrSums := iCurrSums + 1;
  537.       case myMap[i].ActiveFlag of
  538.         diActive: iActiveSums := iActiveSums + 1;
  539.         diAsNeeded: iNeededSums := iNeededSums + 1;
  540.       end;
  541.     end;
  542.   end;
  543.   nActiveDims.caption := inttostr(iActiveDims);
  544.   nActiveSums.caption := inttostr(iActiveSums);
  545.   nDemandDims.caption := inttostr(iNeededDims+iActiveDims);
  546.   nDemandSums.caption := inttostr(iNeededSums+iActiveSums);
  547.   nCurrDims.caption := inttostr(iCurrDims);
  548.   nCurrSums.caption := inttostr(iCurrSums);
  549.   if (iActiveCP > 0) and (iNeededCP > 0) then
  550.     nDemandCells.Caption := inttostr((iNeededSums + iActiveSums) * iActiveCP * iNeededCP)
  551.   else
  552.     nDemandCells.Caption := sNotAvailable;
  553.   if (iCurrCP > 0) then
  554.     nCurrCells.Caption := IntToStr(iCurrCP * iCurrSums)
  555.   else
  556.     nCurrCells.Caption := sNotAvailable;
  557. end;
  558.  
  559. procedure TDssCubeEditor.radioMetaDataClick(Sender: TObject);
  560. begin
  561.   myObject.DesignState := dsMetaData;
  562. end;
  563.  
  564. procedure TDssCubeEditor.RadioDimensionDataClick(Sender: TObject);
  565. begin
  566.   myObject.DesignState := dsDimensionData;
  567. end;
  568.  
  569. procedure TDssCubeEditor.RadioAllDataClick(Sender: TObject);
  570. begin
  571.   myObject.DesignState := dsAllData;
  572. end;
  573.  
  574. procedure TDssCubeEditor.RadioNoDataClick(Sender: TObject);
  575. begin
  576.   myObject.DesignState := dsNoData;
  577. end;
  578.  
  579. procedure TDssCubeEditor.OKButtonClick(Sender: TObject);
  580. begin
  581.   try
  582.     SFinalize;
  583.   except
  584.     on E: exception do
  585.     begin
  586.       raise Exception.create(E.Message);
  587.       Exit;
  588.     end;
  589.   end;
  590.   Close;
  591. end;
  592.  
  593. procedure TDSSCubeEditor.HandleFieldEdit(Sender: TObject);
  594. var
  595.   DM: TCubeDim;
  596. begin
  597.   if (Sender = FormatEdit) then
  598.   begin
  599.     bEditing := true;
  600.     if (TEdit(Sender).text <> '') then FFormatCopy := TEdit(Sender).text;
  601.   end;
  602.   if (Sender = CaptionEdit) then
  603.   begin
  604.     bEditing := true;
  605.     if (TEdit(Sender).text <> '') then FNameCopy := TEdit(Sender).text;
  606.   end;
  607.   if (Sender = BaseNameEdit) then bEditing := true;
  608.   if (Sender = ActiveEdit) then
  609.   begin
  610.     bEditing := true;
  611.     FActiveCopy := TActiveFlags(TComboBox(Sender).itemindex);
  612.   end;
  613.   if (Sender = TypeEdit) then
  614.   begin
  615.     bEditing := true;
  616.     FTypeCopy := TDimFlags(TComboBox(Sender).itemindex);
  617.   end;
  618.   if (Sender = BinEdit) then
  619.   begin
  620.     bBinEdited := true;
  621.     bEditing := true;
  622.     FBinTypeCopy := TBinType(TComboBox(Sender).itemindex);
  623.     DM := myMap[fLastSelected];
  624.     if (FBinTypeCopy <> DM.BinType) then
  625.     begin
  626.       if (FBinTypeCopy in [binQuarter, binYear, binMonth])then
  627.       begin
  628.         if (DM.FieldType in [ftDate,ftDateTime]) then
  629.         begin
  630.           FStartValueCopy := TCubeDim(DM).StartValue;
  631.           StartEdit.text := TCubeDim(DM).StartValue;
  632.           StartEdit.enabled := true;
  633.           StartLabel.enabled := true;
  634.         end
  635.         else
  636.         begin
  637.           ShowMessage(sDateBinningNotAllowed);
  638.           TComboBox(Sender).itemIndex := 0;
  639.         end;
  640.       end
  641.       else if (FBinTypeCopy = binSet) then
  642.       begin
  643.         StartEdit.enabled := true;
  644.         StartEdit.text := '';
  645.         StartLabel.enabled := true;
  646.       end
  647.       else
  648.       begin
  649.         StartEdit.Text := '';
  650.         StartEdit.enabled := false;
  651.         StartLabel.enabled := false;
  652.       end;
  653.     end;
  654.   end;
  655.   if (Sender = StartEdit) then
  656.   begin
  657.     bEditing := true;
  658.     bBinEdited := true;
  659.   end;
  660. end;
  661.  
  662. procedure TDSSCubeEditor.HandleBeginEdit(Sender: TObject; var Key: Char);
  663. begin
  664.   bEditing := true;
  665. end;
  666.  
  667. procedure TDSSCubeEditor.ActiveEditChange(Sender: TObject);
  668. begin
  669.   bEditing := true;
  670. end;
  671.  
  672. procedure TDSSCubeEditor.CancelButtonClick(Sender: TObject);
  673. begin
  674.   Close;
  675. end;
  676.  
  677. procedure TDSSCubeEditor.PagerChange(Sender: TObject);
  678. begin
  679.   CommitEdit;
  680.   if (Pager.ActivePage.Name = 'MemoryControl') then
  681.     InitCapacityPage;
  682. end;
  683.  
  684. procedure TDSSCubeEditor.GetValueCounts;
  685. var
  686.   Map: TCubeDims;
  687.   i: integer;
  688.   Cells, Dims, Sums: integer;
  689.   dState: TCubeDataState;
  690. begin
  691.   Map := TCubeDims.create(myObject, TCubeDim);
  692.   dState := myObject.DesignState;
  693.   Dims := strtoint(MaxDims.text);
  694.   Sums := strtoint(maxSums.text);
  695.   Cells := strtoint(maxCells.text);
  696.   try
  697.     Map.assign(myMap);
  698.     myObject.maxDimensions := 16;
  699.     myObject.maxSummaries := 32;
  700.     myObject.maxCells := 200000000;
  701.     for i := 0 to Map.count-1 do
  702.       Map[i].ActiveFlag := diAsNeeded;
  703.     myObject.DesignState := dsDimensionData;
  704.     if assigned(myObject.DataSet) then
  705.     begin
  706.       bForceRefresh := true;
  707.       if (myObject.DataSet.Active) then
  708.         myObject.Refresh(Map, true)
  709.       else
  710.       begin
  711.         if assigned(myObject.DimensionMap) then
  712.           myObject.DimensionMap.assign(Map);
  713.         myObject.DataSet.Active := true;
  714.       end;
  715.       for i := 0 to myMap.count-1 do
  716.         myMap[i].ValueCount := myObject.DimensionMap[i].ValueCount;
  717.     end;
  718.   finally
  719.     Map.free;
  720.     myObject.DesignState := dstate;
  721.     myObject.MaxDimensions := Dims;
  722.     myObject.MaxSummaries := Sums;
  723.     myObject.MaxCells := Cells;
  724.   end;
  725. end;
  726.  
  727. procedure TDSSCubeEditor.GetCellCountsClick(Sender: TObject);
  728. begin
  729.   GetValueCounts;
  730.   UpdateLists;
  731.   InitCapacityPage;
  732. end;
  733.  
  734. procedure TDSSCubeEditor.FormKeyPress(Sender: TObject; var Key: Char);
  735. begin
  736.   if (Key = Chr(13)) then
  737.     OKButtonClick(Self)
  738.   else if (Key = Chr(27)) then
  739.     CancelButtonClick(self);
  740. end;
  741.  
  742. procedure TDSSCubeEditor.HelpButtonClick(Sender: TObject);
  743. begin
  744.   Application.HelpContext(hcDDecisionCubeEditor);
  745. end;
  746.  
  747. end.
  748.